﻿#region Using Statements
using System;
using GameBase.Screens;
using Microsoft.Xna.Framework;
#endregion

namespace StarFox.ScreenComponents
{
    /// <summary>
    /// Implementation of a head-up display.
    /// <para>Definition of bar and icon items.</para>
    /// </summary>
    partial class HeadUpDisplay
    {
        #region Fuel

        Point initPosFuel;
        Point endPosFuel;
        Rectangle dstRectFuel;

        HudBar fuelBar;
        readonly int fuelBarHeight = 15;

        Vector2 posFuelPercent;
        string fuelPercentText = "100%";

        /// <summary>
        /// Sets the StarShip's fuel level available.
        /// </summary>
        public float Fuel
        {
            set
            {
                // fuel bar value
                fuelBar.Value = MathHelper.Clamp(value, 0.0f, 1.0f);

                // fuel percent value
                double auxValue = Math.Round(fuelBar.Value * 100, 0);
                fuelPercentText = auxValue.ToString() + "%";
                posFuelPercent.X = dstRectFuel.Width - smallFont.MeasureString(fuelPercentText).X * Screen.Scale;
            }
        }

        #endregion

        #region Health

        Point initPosHealth;
        Point endPosHealth;
        Rectangle dstRectHealth;

        HudBar healthBar;
        readonly int healthBarHeight = 15;

        /// <summary>
        /// Sets the StarShip's health level available.
        /// </summary>
        public float Health
        {
            set
            {
                healthBar.Value = MathHelper.Clamp(value, 0.0f, 1.0f);
            }
        }

        #endregion

        #region Boost

        Point initPosBoost;
        Point endPosBoost;
        Rectangle dstRectBoost;

        HudBar boostBar;
        readonly int boostBarHeight = 15;

        /// <summary>
        /// Sets the StarShip's boost level available.
        /// </summary>
        public float BoostLevel
        {
            set
            {
                boostBar.Value = MathHelper.Clamp(value, 0.0f, 1.0f);
            }
        }

        #endregion

        #region Bombs

        Point initPosBomb;
        Point endPosBomb;
        int distToBomb;
        Rectangle dstRectBomb;

        /// <summary>
        /// Sets the StarShip's number of bombs available.
        /// </summary>
        public int Bombs
        {
            private get;
            set;
        }

        #endregion

        private void HeadUpDisplay_Bars()
        {
            #region Fuel

            Rectangle auxRect = spriteSheet.SourceRectangle("BAR_FUEL");
            dstRectFuel = Rectangle.Empty;
            dstRectFuel.Width = (int)(auxRect.Width * Screen.Scale);
            dstRectFuel.Height = (int)(auxRect.Height * Screen.Scale);
            initPosFuel = new Point(-dstRectFuel.Width * 3, (int)(Screen.Height * 0.75f));
            endPosFuel = new Point((int)(Screen.Width * 0.025f), initPosFuel.Y);
            dstRectFuel.Location = initPosFuel;

            posFuelPercent.X = dstRectFuel.Width - smallFont.MeasureString(fuelPercentText).X * Screen.Scale;
            posFuelPercent.Y = -(int)(Screen.Height * 0.01f);

            fuelBar = new HudBar(Screen, dstRectFuel.Width, (int)(fuelBarHeight * Screen.Scale))
            {
                Color = Color.Gold,
                Value = 1.0f,
                Y = dstRectFuel.Location.Y + dstRectFuel.Height + (int)(Screen.Height * 0.0125f)
            };

            #endregion

            #region Health

            auxRect = spriteSheet.SourceRectangle("BAR_HEALTH");
            dstRectHealth = Rectangle.Empty;
            dstRectHealth.Width = (int)(auxRect.Width * Screen.Scale);
            dstRectHealth.Height = (int)(auxRect.Height * Screen.Scale);
            initPosHealth.X = -dstRectHealth.Width * 2;
            initPosHealth.Y = fuelBar.Y + fuelBar.Height + (int)(Screen.Height * 0.0125f);

            endPosHealth = new Point((int)(Screen.Width * 0.025f), initPosHealth.Y);
            dstRectHealth.Location = initPosHealth;

            healthBar = new HudBar(Screen, dstRectHealth.Width, (int)(healthBarHeight * Screen.Scale))
            {
                Color = Color.Chartreuse,
                Value = 1.0f,
                Y = dstRectHealth.Location.Y + dstRectHealth.Height + (int)(Screen.Height * 0.0125f)
            };

            #endregion

            #region Boost Bar

            boostBar = new HudBar(Screen, dstRectHealth.Width, (int)(boostBarHeight * Screen.Scale))
            {
                Color = Color.Aqua,
                Value = 1.0f,
                Y = healthBar.Y + healthBar.Height + (int)(Screen.Height * 0.0125f)
            };

            auxRect = spriteSheet.SourceRectangle("BAR_BOOST");
            dstRectBoost = Rectangle.Empty;
            dstRectBoost.Width = (int)(auxRect.Width * Screen.Scale);
            dstRectBoost.Height = (int)(auxRect.Height * Screen.Scale);
            initPosBoost.X = -dstRectBoost.Width;
            initPosBoost.Y = boostBar.Y + boostBar.Height + (int)(Screen.Height * 0.0125f);

            endPosBoost = new Point((int)(Screen.Width * 0.025f), initPosBoost.Y);
            dstRectBoost.Location = initPosBoost;

            #endregion

            #region Bombs

            auxRect = spriteSheet.SourceRectangle("ICON_BOMB");
            dstRectBomb = Rectangle.Empty;
            dstRectBomb.Width = (int)(auxRect.Width * Screen.Scale);
            dstRectBomb.Height = (int)(auxRect.Height * Screen.Scale);
            initPosBomb = new Point(initPosFuel.X * 3, (int)(Screen.Height * 0.675f));
            endPosBomb = new Point((int)(Screen.Width * 0.040f), initPosBomb.Y);
            dstRectBomb.Location = initPosBomb;
            distToBomb = (int)(dstRectBomb.Width * 1.40f);

            #endregion
        }
    }
}
